const Actions = require('./actions');
const DB = require('app/db');

module.exports = Reflux.createStore({
    listenables: [Actions],
    data: {

    },

    onFetchStudentInfo: function (params, cb) {
        let t = this;
        DB.Teacher.get_student_detail({
            schoolId: params.schoolId||'f20171120',
            studentId: params.studentId
        })
            .then((content) => {
                if (content.code == 1) {
                    let schoolId = content.check.schoolId;
                    let studentId = content.check.studentId;
                    content = content.data;
                    let {
                        studnetSex,//学生信息性别-item
                        parentList,//家长信息-item
                        studentCode,//学生信息学号-item
                        studentName,//学生名字-头
                        dormitory,//学生信息宿舍-item
                        className,//学生信息班级-item
                        itemsName,//学生信息学习科目-item
                        studentAddr,//学生信息家庭地址-item
                        studentHeadUrl//头像地址-头
                    } = content;
                    this.data.headData = { studentHeadUrl, studentName };
                    this.data.itemData = {
                        studnetSex,//学生信息性别-item
                        parentList,//家长信息-item
                        studentCode,//学生信息学号-item
                        dormitory,//学生信息宿舍-item
                        className,//学生信息班级-item
                        itemsName,//学生信息学习科目-item
                        studentAddr,//学生信息家庭地址-item
                    }
                    return { studentId, schoolId }
                }
            }).then((params) => {
                DB.Teacher.get_student_warnlists({
                    schoolId: params.schoolId,
                    teacherId: 4732,
                    studentId: params.studentId
                })
                    .then((content) => {
                        if (content.code == 1) {
                            content = content.data.list;
                            if (content && content.length > 0) {
                                if (content && content.length > 0) {
                                    for (let item of content) {
                                        item.studentId = params.studentId;
                                        item.teacherId = params.teacherId||4732;
                                        item.schoolId = params.schoolId;
                                    }
                                }
                                t.data.warnList = content;
                            }
                            t.updateComponent();
                        }
                    })
            })
            .catch(function (error) {

            });
    },

    updateComponent: function () {
        this.trigger(this.data);
    }
});
